package com.tuo51.evaluate.vo.evaluate;

import com.tuo51.evaluate.domain.evaluatingV2.EvaluateV2Item;
import com.tuo51.evaluate.domain.evaluatingV2.EvaluateV2Question;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class EvaluateV2ItemVO {
    private String id;

    private Date created ;

    private Boolean deleted ;

    private String dimensionId;

    private Integer dimensionCode;

    private String dimensionName;

    private Integer month = 0;

    private Integer score;

    private Integer questionCount = 0;

    private Boolean beginAt = false;

    private Integer restUnpassToNextDimension;


    private List<EvaluateV2QuestionVO> questions;

    public static EvaluateV2ItemVO ofEntity(EvaluateV2Item item, List<EvaluateV2Question> questions){

        List<EvaluateV2QuestionVO> qvos = null;

        if (questions != null) {
            qvos = questions.stream().map(k ->{
                EvaluateV2QuestionVO ret = EvaluateV2QuestionVO.of(k);

                return ret;
            }).collect(Collectors.toList());
        }


        return of(item, qvos);
    }

    public static EvaluateV2ItemVO of(EvaluateV2Item item, List<EvaluateV2QuestionVO> questions){
        EvaluateV2ItemVO ret = new EvaluateV2ItemVO();

        ret.setId(item.getId());
        ret.setCreated(item.getCreated());
        ret.setDeleted(item.getDeleted());
        ret.setDimensionId(item.getDimensionId());
        ret.setDimensionName(item.getDimensionName());
        ret.setDimensionCode(item.getDimensionCode());
        ret.setMonth(item.getMonth());
        ret.setScore(item.getScore());
        ret.setQuestionCount(item.getQuestionCount());
        ret.setRestUnpassToNextDimension(item.getRestUnpassToNextDimension());

//        CopyUtils.copyProperties(item, ret);
        if (questions != null) {
            ret.setQuestions(questions);
//            ret.setQuestions(questions.stream().map(k->EvaluateV2QuestionVO.ofWithoutTools(k)).collect(Collectors.toList()));
        }

        return ret;
    }
}
